package com.iot08.api.service;

import com.alibaba.fastjson.JSONObject;
import com.iot08.api.config.redis.RedisClusterService;
import com.iot08.api.service.supplement.KafkaService;
import com.iot08.api.vo.request.DateParamReqVO;
import com.iot08.api.vo.request.TargetParamReqVO;
import com.iot08.common.constant.Const;
import com.iot08.common.constant.ConstCacheField;
import com.iot08.common.constant.ConstKafka;
import com.iot08.common.entity.app.Device;
import com.iot08.common.entity.app.DeviceStepDaily;
import com.iot08.common.entity.app.DeviceStepSet;
import com.iot08.common.service.base.BaseService;
import com.iot08.common.utils.DateUtil;
import com.iot08.common.utils.response.ResponseEnum;
import com.iot08.common.utils.response.ResponseMap;
import lombok.extern.slf4j.Slf4j;
import org.bson.types.ObjectId;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * @version 1.0
 * @Description:
 * @author: Rock
 * @time: 2021/1/23 16:34
 */
@Slf4j
@Service
public class DeviceStepSetService extends BaseService<DeviceStepSet> {

    public DeviceStepSet findByImei(String imei) {
        return this.findById(imei);
    }


    public DeviceStepSet create(String imei ,Integer target) {

        DeviceStepSet deviceStepSet = new DeviceStepSet();
        deviceStepSet.setId(imei);
        deviceStepSet.setSwitchStatus(0);
        deviceStepSet.setTarget(target);
        return this.save(deviceStepSet);
    }

    @Override
    public DeviceStepSet save(DeviceStepSet deviceStepSet) {
        //所有记录的失效时间天数 3个月
        deviceStepSet.setUpdateTime(DateUtil.nowTimestampToLong());
        deviceStepSet.setExpiryAt(DateUtil.getSystemExpiryAt());
        return mongoTemplate.save(deviceStepSet);
    }



}
